import React from 'react'
import { ModalForm } from '@ant-design/pro-form';
import { ProFormSelect, ProFormTextArea } from '@ant-design/pro-form';
import { getAddRecords } from '@/services/records';
import { history } from 'umi';
import { message } from 'antd';
export default function AddRecords() {
  const { id, uid } = history.location.query ?? {}
  return (
    <div>
      <ModalForm
        title='添加沟通记录'
        submitter={{
          searchConfig: {
            submitText: '确认',
            resetText: '取消',
          },
        }}
        modalProps={{

        }}
        layout="horizontal"
        visible={true}
        onFinish={async (values) => {

          const res = await getAddRecords({
            ...values, courseId: id, uid: uid
          })
          if (res.success) {
            message.success('添加成功')
          }

        }}
      >
        <div style={{ width: '50%', margin: 'auto' }}>
          <ProFormSelect
            name="object"
            label="沟通对象"
            width="md"
            fieldProps={{
              // onChange: (val) => handleChange(val)
            }}
            initialValue={'0'}
            params={{

            }}
            valueEnum={{
              0: '请选择',
              1: "爸爸",
              2: "妈妈",
              3: "爷爷",
              4: "奶奶",
              5: "姥姥",
              6: "姥爷",
              7: "其他",
            }}
            rules={[
              { required: true, message: '请选择沟通对象' },
              { pattern: /^[1-9]$/, message: '请选择沟通对象' }
            ]}
          />
          <ProFormSelect
            name="purpose"
            label="沟通目的"
            width="md"
            fieldProps={{
              // onChange: (val) => handleChange(val)
            }}
            initialValue={'0'}
            params={{

            }}
            valueEnum={{
              0: '请选择',
              1: "日常沟通",
              2: "续报沟通",
              3: "退费沟通",
              4: "特殊情况沟通",
            }}
            rules={[
              { required: true, message: '请选择沟通目的' },
              { pattern: /^[1-9]$/, message: '请选择沟通目的' }
            ]}
          />
          <ProFormTextArea
            name="content"
            label="沟通内容"
            placeholder="请输入名称"
            fieldProps={{
              showCount: true, maxLength: 500, placeholder: "请输入沟通内容",
            }}
            rules={[{ required: true, message: '请输入沟通内容' }]}
          />
        </div>
      </ModalForm>
    </div>
  )
}
